home *** CD-ROM | disk | FTP | other *** search
- /*
- * Objects-In-C test program
- *
- * Copyright © John Wainwright 1988
- *
- */
-
- #include <stdio.h>
- #include "oic.h"
- #include "generics.h"
-
- enum { TITLE = 1, BOUNDS, KIND };
- extern class Window;
-
- main()
- {
- object p1, p2;
- object box1, box2;
- object list1, list2;
- object seq, item;
- register int i;
- register long time;
- extern class Coord, Box, Window;
- object d, w;
- static Rect bounds = {100, 100, 350, 350};
-
- MaxApplZone();
- InitOIC();
- InitSysClasses();
- InitTestClasses();
-
- /*
- TraceClass(List);
- TraceOn();
- */
-
- /*
- * play with strings & lists
- */
-
- print(New(String, "hello world"));
- list1 = New(List,
- New(String, "one"),
- New(String, "two"),
- New(String, "three"), END);
- print(list1);
- print(head(list1));
- print(tail(list1));
- print(list1);
- print(add(list1, New(String, "four"),
- New(List,
- New(String, "one"),
- New(String, "two"),
- New(String, "three"), END), END));
-
- /*
- * Coords & Boxes
- */
-
- print((p1 = New(Coord, 100.0, 100.0)));
- offset(p1, 2.0, 4.0);
- print(p1);
- p2 = New(Coord, 200.0, 200.0);
- print((box1 = New(Box, 100.0, 100.0, 200.0, 200.0)));
-
- /*
- * add different things to the original list
- */
- add(list1, p1, box1, New(List, box1, p1, END), END);
- print(list1);
- print(push(list1, p1));
- printf("%s %s\n", ClassNameOf(list1), ClassNameOf(p1));
-
- /*
- * experiment with the sequencing classes
- */
-
- for (seq = sequence(list1); item = next(seq);)
- print(item);
-
- /*
- * or, more simply, using the "map" generic
- */
-
- map(list1, print);
-
- /*
- * Coords inherit from indexMixin which keeps track of
- * all instances - it provides a class method for "sequence"
- * to allow us to simply sequence over all instances
- * see how neat it all is ?
- */
- printf("\nall Coord instances...\n");
- for (seq = sequence(Coord); item = next(seq);)
- {
- printf("-> "); print(item);
- }
-
- /*
- * indexMixin can find ALL its kept instances ...
- */
- printf("\nall indexMixin deepinstances...\n");
- for (seq = sequence(deepInstances(IndexMixin)); item = next(seq);)
- {
- printf("-> "); print(New(List, item, className(item), END));
- }
-
- /*
- * playing with other kind of list
- */
- printf("\ntrying alternate list classes...\n");
- list2 = New(List2);
- add(list2, New(String, "one"),
- New(String, "two"),
- New(String, "three"), END);
- print(list2);
-
- /*
- * timing differences in making the 2 different list kinds
- */
- printf("\nmaking a 1000 element list\n");
- time= TickCount();
- list1 = New(List, END);
- for (i = 0; i < 1000; i++)
- push(list1, p1);
- printf("done... sequencing it...\n");
- for (i = 0, seq = sequence(list1); item = next(seq); )
- i++;
- printf("done, found %d items, %ld ticks\n", i, TickCount() - time);
-
- printf("making a 1000 element list2\n");
- time= TickCount();
- list2 = New(List2);
- for (i = 0; i < 1000; i++)
- push(list2, p1);
- printf("done... sequencing it...\n");
- for (i = 0, seq = sequence(list2); item = next(seq); )
- i++;
- printf("done, found %d items, %ld ticks\n", i, TickCount() - time);
-
- /*
- * the class Class has a number of useful methods ...
- */
- printf("\nall Object subclasses...\n");
- print(subs(Object));
-
- printf("all Collect subclasses...\n");
- print(subs(Collect));
-
- printf("all List2 supers...\n");
- print(supers(List2));
-
- /*
- * play around with the very simple window class. Note that
- * it uses List as a mixin to provide a simple contents list.
- * I am also experimenting with keyword parameters, a la Lisp -
- * see window.c see & key_arg() in oic.h for details
- */
- w = New(Window, BOUNDS, &bounds,
- TITLE, "\pJohn's",
- KIND, (long)rDocProc,
- END);
-
- add(w, box1, New(Box, 150.0, 150.0, 190.0, 190.0), END);
- draw(w);
- print(w);
-
- printf("all done\n");
- }
-
- InitTestClasses()
- {
- InitCoordClass();
- InitBoxClass();
- InitWindowClass();
- }
-